import { Session } from '@/utils/storage';
import { Module } from 'vuex';
import {login} from "@/api/api";

const { VITE_TOKEN_KEY, VITE_UID_KEY } = import.meta.env;
const token = Session.get('ZJ_token');

interface StoreUser {
  token: string;
  user: AnyObject;
  userInfo: object
  signInData: object
}

const store: Module<StoreUser, unknown> = {
  // namespaced: true,
  state() {
    return {
      token: token,
      user: {},
      userInfo: {},
      signInData: {},
      IMStatus: '0'
    };
  },
  mutations: {
    setSignIn(state, data){
      if(Object.keys(data).length > 0){
        state.userInfo = data
      }
    },
    setUser(state, user){
      if(Object.keys(user).length > 0){
        state.signInData = user
        console.log(state.signInData)
      }
    },
    setIM(state,data){
      state.IMStatus = data
    }
  },
  actions: {
    setSignIn(context, data) {
      context.commit('setSignIn', data)
    },
    setUser({ commit }, user) {
      console.log(user)
      commit('setUser', user)
    },
    getUser({ commit }) {
      
    },
    setIM({commit},data){
      commit('setIM',data)
    }
  }
};

export default store;
